package com.lpc.contentprovidertest;

import android.content.ContentProvider;
import android.content.ContentValues;
import android.content.UriMatcher;
import android.database.Cursor;
import android.net.Uri;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.Log;

/**
 * 功能:
 * <p>
 * 描述:
 * <p>
 * Created by lipc0113 on 2018/7/11.
 */
public class MyContentProvider extends ContentProvider {

    public static String test;

    static UriMatcher uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);

    private static final int insert = 0x10;

    private static final int delete = 0x11;

    private static final int update = 0x12;

    private static final int query = 0x13;

    static {

        uriMatcher.addURI("com.lpc.contentprovidertest.MyContentProvider", "insert", insert);
        uriMatcher.addURI("com.lpc.contentprovidertest.MyContentProvider", "delete", delete);
        uriMatcher.addURI("com.lpc.contentprovidertest.MyContentProvider", "update", update);
        uriMatcher.addURI("com.lpc.contentprovidertest.MyContentProvider", "query", query);
    }

    @Override
    public boolean onCreate() {

        test = "init";
        return false;
    }

    @Nullable
    @Override
    public Cursor query(@NonNull Uri uri, @Nullable String[] strings, @Nullable String s, @Nullable String[] strings1, @Nullable String s1) {

        int match = uriMatcher.match(uri);
        if(match == query){

        }
        return null;
    }

    @Nullable
    @Override
    public String getType(@NonNull Uri uri) {
        return null;
    }

    @Nullable
    @Override
    public Uri insert(@NonNull Uri uri, @Nullable ContentValues contentValues) {

        int match = uriMatcher.match(uri);
        if(match == insert){

        }
        return null;
    }

    @Override
    public int delete(@NonNull Uri uri, @Nullable String s, @Nullable String[] strings) {

        int match = uriMatcher.match(uri);
        if(match == delete){
            test = "delete";
            Log.e("lipc0113", test);
            getContext().getContentResolver().notifyChange(uri, null);
            return 1;
        }
        return 0;
    }

    @Override
    public int update(@NonNull Uri uri, @Nullable ContentValues contentValues, @Nullable String s, @Nullable String[] strings) {

        int match = uriMatcher.match(uri);
        if(match == update){
            test = "update";
            Log.e("lipc0113", test);
            getContext().getContentResolver().notifyChange(uri, null);
            return 1;
        }
        return 0;
    }
}
